home *** CD-ROM | disk | FTP | other *** search
- Path: news.PBI.net!usenet
- From: mich@pbinet.com
- Newsgroups: comp.lang.c
- Subject: Re: free() wont free
- Date: 9 Mar 1996 16:49:42 GMT
- Organization: Pacific Bell Internet Services
- Message-ID: <4hscr6$efq@SNFC21_SRVR_WWW.PBI.net>
- References: <31398D95.5701DCB4@halo.tau.ac.il> <4hn41e$2dh@druid.borland.com>
- Reply-To: mich@pbinet.com
- NNTP-Posting-Host: ppp-5-36.rdcy01.pbinet.com
- X-Newsreader: IBM NewsReader/2 v1.03
-
- In <4hn41e$2dh@druid.borland.com>, pete@borland.com (Pete Becker) writes:
- > Second, assume that free() does its job. The problem is not that
- >free() doesn't work, but that your program allocates memory that it never
- >frees. Track through all of the memory allocations that it does, find out
- >where the leaks are, and fix them. If you can't find the leaks you aren't
- >looking hard enough.
-
- Yes, assuming free has infact freed memory blocks is about all you can do.
- For allocation problems, look for freeing the same pointer more than once. This
- is a common mistake. Consider;
-
- myfunc()
- {
- void *pMem = malloc(100);
- free(pMem);
- free(pMem);
- }
-
- At best the results of this will be unpredictable. Look for attempts to free invalid
- pointers, or requests to allocate already allocated ones. And always check the
- pointer after allocating, it can save you hours of debugging. malloc is really a
- request, not a command. For whatever reason the system my not be able to
- allocate your request everytime. malloc returns a null pointer in these cases.
-
-